/**
 * Created by lxy_920912 on 2017/1/16.
 */
var numSquares = function(n) {

    var result = [];
    result[0] = 0;
    for(var i = 1;i <= n;i++){
        result[i] = i;
        for(var j = 0;j * j <= i;j++){
            var num = result[i-(j*j)]+1;
            if(num < result[i]){
                result[i] = num;
            }
        }
    }
    return result[n];

};
